package com.qf.FinancialManagement.controller;

import com.qf.FinancialManagement.domain.TmsAll;
import com.qf.FinancialManagement.service.TmsAllService;
import com.qf.common.core.controller.BaseController;
import com.qf.common.core.domain.AjaxResult;
import com.qf.common.core.page.TableDataInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * ---好运常在---
 *
 * @author ChengShuaiKe
 * @date 2025/9/4 0004
 * @desc
 */
@RestController
@RequestMapping("/finance/complete")
public class TmsAllController extends BaseController {
    @Autowired
    private TmsAllService tmsAllService;

    /**
     * 展示所有数据
     * @param params
     * @return
     */
    @RequestMapping("/list")
    public TableDataInfo list(@RequestParam Map<String, Object> params) {
        startPage();
        List<TmsAll> list = tmsAllService.selectAll(params);
        return getDataTable(list);
    }


    /**
     * 批量删除
     */
    @DeleteMapping("/{ids}")
    public AjaxResult delAll(@PathVariable Long[] ids) {
        return toAjax(tmsAllService.deleteTmsAllByIds(ids));
    }

    /**
     * 修改的时候,先查询详情,再修改
     */
    @GetMapping("/{id}")
    public AjaxResult get(@PathVariable Long id) {
        return AjaxResult.success(tmsAllService.selectTmsById(id));
    }

    /**
     * 更新
     */
    @PutMapping("/{id}")
    public AjaxResult edit(@PathVariable Long id, @RequestBody TmsAll tmsAll) {
        // 更严格的ID校验
        if (id == null || id <= 0) {
            return AjaxResult.error("ID不能为空且必须为正整数");
        }
        // 确保对象中的ID与路径ID一致
        if (tmsAll.getId() != null && !tmsAll.getId().equals(id)) {
            return AjaxResult.error("请求路径中的ID与对象ID不一致");
        }
        // 设置对象ID为路径ID（确保一致性）
        tmsAll.setId(id);


        return toAjax(tmsAllService.update(tmsAll));
    }
    /**
     * 新增
     */
    @PostMapping
    public AjaxResult add(@RequestBody TmsAll tmsAll) {
        // 设置创建时间
        tmsAll.setCreateTime(new Date());
        return toAjax(tmsAllService.add(tmsAll));
    }
}

